<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var haystack = 'aaa';
        var needle = 'aaa'
        // 双指针
        var strStr = function (haystack, needle) {
            var hl = haystack.length;
            var nl = needle.length;

            if (nl == 0) {
                return 0
            }

            var h = 0;
            var n = 0;
            var cur = 0;
            while (h < hl) {
                if (haystack[h] == needle[n]) {
                    h++;
                    n++;
                    cur++;
                } else {
                    h = h - cur + 1;
                    n = 0;
                    cur = 0;
                }

                if (cur == nl) {
                    break
                }
            }
            console.log(cur, nl);
            return cur == nl ? h - cur : -1
        };
        console.log(strStr(haystack, needle));



        // var subsets = function (nums) {
        //     var out = [[]];
        //     for (var i = 0; i < nums.length; i++) {
        //         var outTemp = JSON.parse(JSON.stringify(out));
                

        //         for (var j = 0; j < outTemp.length; j++) {
        //             outTemp[j].push(nums[i])
        //         }
        //         out = out.concat(outTemp);
                
        //     }
        //     console.log(out);
        //     return out
        // };

        // 递归回溯
        var subsets = function(nums){
            var res = [];
            var temp = [];
            let back = (temp,start)=>{
                res.push(temp);
                for(var i =start;i<nums.length;i++){
                    temp.push(nums[i]);
                    back(temp.slice(),i+1);
                    temp.pop()
                }
                console.log(res);
            }
            back(temp,0)
            return res
        }

console.log(subsets([1,2,3]));
        
    </script>
</body>

</html>